﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models;
using System.Data;
using System.Data.SqlClient;
using DAL;


namespace DAL
{
    public  class supDAL
    {
        //public IList<supmodel> show()
        //{ 
        //   IList<supmodel> su=new List<supmodel>();
        //   supmodel s;
        //   string sqlstr = "select  name from supplier";

        //   DataTable dt = sqlHelper.getTable(sqlstr);
        //   foreach (DataRow row in dt.Rows)
        //   {
        //       s = new supmodel();
        //       s.name = row["name"].ToString();
        //       su.Add(s);
        //   }
        //   return su;
        //}
        //public string haha()
        //{
        //    string sqlstr = "select  name from supplier";
        //    SqlConnection conn = new SqlConnection(@"Data Source=.;Initial Catalog=Manage;Integrated Security=True");
        //    conn.Open();
            
        //    SqlCommand cmd = new SqlCommand(sqlstr,conn);
        //    SqlDataReader dr = cmd.ExecuteReader();
        //    string mm = "";
        //    while (dr.Read())
        //    {
        //        mm = mm+dr["name"].ToString() +"\n";
        //    }
        //    return mm;
        //}

        //返回供应商信息
        public IList<supmodel> getTable()
        { 
           IList<supmodel> su=new List<supmodel>();
           supmodel s;
           string sqlstr = "select id,name,tel,address from supplier";
           DataTable dt = sqlHelper.getTable(sqlstr);
            foreach(DataRow row in dt.Rows)
            {
                s = new supmodel();
                s.id = Convert.ToInt32(row["id"]);
                s.name=row["name"].ToString();
                s.tel = row["tel"].ToString();
                s.address = row["address"].ToString();
                su.Add(s);
            }
            return su;
        }


        public IList<supmodel> getdata(string hh)
        {
            IList<supmodel> su = new List<supmodel>();
            supmodel s;
            string sqlstr = "select id,name,tel,address from supplier where name='"+hh+"'";
            DataTable dt = sqlHelper.getTable(sqlstr);
            foreach (DataRow row in dt.Rows)
            {
                s = new supmodel();
                s.id = Convert.ToInt32(row["id"]);
                s.name = row["name"].ToString();
                s.tel = row["tel"].ToString();
                s.address = row["address"].ToString();
                su.Add(s);
            }
            return su;
        }
    }
}
